home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Auge 4000 / Auge 4000 #17 (1988-04-01)(Amiga User Gruppe Einzugsgebiet 4000).zip / Auge 4000 #17 (1988-04-01)(Amiga User Gruppe Einzugsgebiet 4000).adf / DrunkenMouse / in.c < prev    next >
C/C++ Source or Header  |  1996-12-24  |  2KB  |  103 lines

  1. /* in.c */
  2. /* by Alex Livshits */
  3. /* July 1987 */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/ports.h>
  7. #include <exec/memory.h>
  8. #include <exec/io.h>
  9. #include <exec/interrupts.h>
  10. #include <devices/input.h>
  11. #include <devices/inputevent.h>
  12.  
  13. #define DEVPORT   0x00000001
  14. #define REQBLOCK  0x00000002
  15. #define INPUT     0x00000004
  16.  
  17. static ULONG mask;
  18.  
  19. /* =======  EXPORT ======== */
  20. int in_start(), in_end(), in_moveptr();
  21. /***/
  22.  
  23. /* =======  IMPORT ========= */
  24. extern int HandlerInterface();
  25. /***/
  26.  
  27. static struct Port *inputDevPort;
  28. static struct IOStdReq *inputRequestBlock;
  29. static struct InputEvent phony;
  30. static struct Interrupt handler;
  31.  
  32.  
  33. int
  34. in_start()
  35. {
  36.    int retc;
  37.  
  38.    mask = 0;
  39.  
  40.    inputDevPort = CreatePort(0,0);
  41.    if (inputDevPort == NULL) return(1);
  42.    mask |= DEVPORT;
  43.  
  44.    inputRequestBlock = CreateStdIO(inputDevPort);
  45.    if(inputRequestBlock == 0) { in_end(); return(2); }
  46.    mask |= REQBLOCK;
  47.  
  48.    retc = OpenDevice("input.device",0,inputRequestBlock,0);
  49.    if (retc) { in_end(); return(3); }
  50.    mask |= INPUT;
  51.  
  52.  
  53.    handler.is_Data = 0;
  54.    handler.is_Code = HandlerInterface;
  55.    handler.is_Node.ln_Pri = 51;
  56.  
  57.    inputRequestBlock->io_Command = IND_ADDHANDLER;
  58.    inputRequestBlock->io_Data = &handler;
  59.    DoIO(inputRequestBlock);
  60.  
  61.    return(0);
  62. }
  63.  
  64. int
  65. in_moveptr(x,y)
  66.    LONG x,y;
  67. {
  68.    phony.ie_NextEvent=NULL;
  69.    phony.ie_Class = IECLASS_POINTERPOS;
  70.    phony.ie_Code=IECODE_NOBUTTON;
  71.    phony.ie_Qualifier = 0; /* IEQUALIFIER_RELATIVEMOUSE; */
  72.    phony.ie_X=x;
  73.    if (y==-1) phony.ie_Y=100;
  74.    else phony.ie_Y=y;
  75.  
  76.    inputRequestBlock->io_Command = IND_WRITEEVENT;
  77.    inputRequestBlock->io_Length=sizeof(struct InputEvent);
  78.    inputRequestBlock->io_Data = &phony;
  79.    DoIO(inputRequestBlock);
  80.  
  81.    return(0);
  82. }
  83.  
  84.  
  85. int
  86. in_end()
  87. {
  88.    if (mask & INPUT)
  89.    {
  90.       inputRequestBlock->io_Command = IND_REMHANDLER;
  91.       inputRequestBlock->io_Data = &handler;
  92.       DoIO(inputRequestBlock);
  93.       CloseDevice(inputRequestBlock);
  94.    }
  95.    if (mask & REQBLOCK) DeleteStdIO(inputRequestBlock);
  96.    if (mask & DEVPORT) DeletePort(inputDevPort);
  97.    return(0);
  98. }
  99.  
  100.  
  101.  
  102.  
  103.